﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Rapid
{
    public partial class TestTemplate : UserControl
    {
        public Test test;
        public EDirection myDirection;

        public TestTemplate()
        {
            InitializeComponent();
        }

        public void Init(Test test, EDirection direction)
        {
            // variable init
            this.test = test;
            this.myDirection = direction;

            // method init
            SetBackground(false);
        }


        private void SetBackground(Bitmap resourceImage)
        {
            this.BackgroundImage = (System.Drawing.Image)resourceImage;
        }

        private void SetBackgroundVertical(bool isHighLight)
        {
            switch (this.test.observation)
            {
                case EObservation.Line:
                    if (isHighLight)
                        SetBackground(Properties.Resources.line_highlight);
                    else
                        SetBackground(Properties.Resources.line);
                    break;
                case EObservation.NoLine:
                    if (isHighLight)
                        SetBackground(Properties.Resources.no_line_highlight);
                    else
                        SetBackground(Properties.Resources.no_line);
                    break;
                default: //Unclear
                    if (isHighLight)
                        SetBackground(Properties.Resources.dot_highlight);
                    else
                        SetBackground(Properties.Resources.dot);
                    break;
            }
        }

        private void SetBackgroundHorizontal(bool isHighLight)
        {
            switch (this.test.observation)
            {
                case EObservation.Line:
                    if (isHighLight)
                        SetBackground(Properties.Resources.h_line_highlight);
                    else
                        SetBackground(Properties.Resources.h_line);
                    break;
                case EObservation.NoLine:
                    if (isHighLight)
                        SetBackground(Properties.Resources.h_no_line_highlight);
                    else
                        SetBackground(Properties.Resources.h_no_line);
                    break;
                default: //Unclear
                    if (isHighLight)
                        SetBackground(Properties.Resources.h_dot_highlight);
                    else
                        SetBackground(Properties.Resources.h_dot);
                    break;
            }
        }

        public void SetBackground(bool isHighLight)
        {
            switch (this.myDirection)
            {
                case EDirection.Vertical:
                    SetBackgroundVertical(isHighLight);
                    break;
                default:
                    SetBackgroundHorizontal(isHighLight);
                    break;
            }
        }

        private void TemplatePanel_MouseHover(object sender, EventArgs e)
        {
            SetBackground(true);
        }

        private void TemplatePanel_MouseLeave(object sender, EventArgs e)
        {
            SetBackground(false);
        }
    }
}
